######
######
###
###News Coverage Analysis
###
######
######
library(dplyr)
library(ggplot2)
library(date)

out = read.delim('MetaData.csv', sep=',')
clean_press<- gsub(' [A-Z][a-z]+ [0-9]+ 201[0-9]', '', out$Press)


date = paste(paste(out[,2], out[,1], sep=''), out[,3], sep='')
date = as.date(date)

use_data<- out[which(out[,5]>0 & out[,6]>0),]


date_use<- paste(paste(use_data[,2], use_data[,1], sep=''), use_data[,3], sep='')
date_use<- as.date(date_use)


nc_data<- out[which(clean_press =='Star News Wilmington NC'),]

nc_date<- as.date(paste(paste(nc_data[,2], nc_data[,1], sep=''), nc_data[,3], sep=''))

hist(nc_date[which(nc_data[,5]>0)], breaks=100)

###let's now break down the data 

nc_data$nc_date<- as.Date(nc_date)

##this is for the star news in wilmington NC

g<- nc_data %>% subset(VoterID>0) %>% ggplot(aes(nc_date)) + 
		geom_histogram() + scale_x_date() + xlab('Date') + 
		ylab('Count') + 
		annotate("text", x = as.Date('2015-06-01'), y = 30, label = c('Law Overturned') , color="black", size=5 , angle=0, fontface="bold") + 
		annotate("segment", x = as.Date('2016-01-01'), xend = as.Date('2016-07-29'), y = 30, yend = 27, colour = "black", size=1, alpha=1, arrow=arrow()) + 
		annotate("text", x = as.Date('2015-8-01'), y = 10, label = c('Election Day') , color="black", size=5 , angle=0, fontface="bold") + 
		annotate("segment", x = as.Date('2015-11-01'), xend = as.Date('2016-11-08'), y = 9, yend = 3, colour = "black", size=1, alpha=1, arrow=arrow()) + 
		ggtitle('Number of Articles About Voter ID Law, Star News (Wilmington NC)')

ggsave(g, file ='figure_a1_left.pdf', height = 6, width = 6)



##doing this now with 
##The New York Times, 
##Washington Post, 
##USA TODAY

national_data<- out[clean_press %in% c('The New York Times', 'Washington Post', 'USA TODAY'),]
nc_date<- as.date(paste(paste(national_data[,2], national_data[,1], sep=''), national_data[,3], sep=''))
national_data$nc_date<- as.Date(nc_date)


g2<- national_data %>% subset(VoterID>0 & NC>0) %>% ggplot(aes(nc_date)) + 
	geom_histogram(bins = 50) + scale_x_date() + xlab('Date') + ylab('Count') + 
	annotate("text", x = as.Date('2015-06-01'), y = 11, label = c('Law Overturned') , color="black", size=5 , angle=0, fontface="bold") + 
		annotate("segment", x = as.Date('2015-11-01'), xend = as.Date('2016-07-29'), y = 11, yend = 10, colour = "black", size=1, alpha=1, arrow=arrow()) + 
		annotate("text", x = as.Date('2015-8-01'), y = 6, label = c('Election Day') , color="black", size=5 , angle=0, fontface="bold") + 
		annotate("segment", x = as.Date('2015-12-01'), xend = as.Date('2016-11-08'), y = 6, yend = 6, colour = "black", size=1, alpha=1, arrow=arrow()) + 
		ggtitle('Number of Articles About Voter ID Law, National Press')

ggsave(g2, file ='figure_a1_right.pdf', height = 6, width = 6)


